package com.lfy.modules.blog.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lfy.modules.blog.domain.HomeDetail;
import com.lfy.modules.blog.domain.group.SaveGroup;
import com.lfy.modules.blog.domain.group.UpdateGroup;
import com.lfy.modules.blog.domain.vo.space.MoodVO;
import com.lfy.modules.blog.service.HomeDetailService;
import com.lfy.modules.blog.service.MoodService;
import com.lfy.modules.common.anno.NoNeedLogin;
import com.lfy.modules.common.custom.constants.PageConstant;
import com.lfy.modules.common.domain.BaseEnum;
import com.lfy.modules.common.domain.PageResultVO;
import com.lfy.modules.common.domain.R;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 说说
 * @author lvfeiyang
 */
@RestController
@RequestMapping("/admin/space")
public class SpaceController {
    @Resource
    private MoodService moodService;
    @Resource
    private HomeDetailService homeDetailService;
    @GetMapping("/list")
    public R<PageResultVO<MoodVO>> list(@RequestParam("pageSize") Integer pageSize, @RequestParam("pageNum")Integer pageNum) {
        if(pageSize > PageConstant.MAX_PAGE_SIZE){
            return R.error(BaseEnum.commonEnum.ERROR_PAGE_SIZE);
        }
        return  moodService.listMood(pageNum, pageSize);
    }
    @GetMapping("/get/title")
    @NoNeedLogin
    public R<HomeDetail> get(@RequestParam("url") String url){

        return homeDetailService.getBlogTitle(url);
    }
    @PostMapping("/save")
    public R<Void> save(@RequestBody @Validated(SaveGroup.class) MoodVO moodVO){
        return this.moodService.saveMood(moodVO);
    }
    @PostMapping("/delete/{id}")
    public R<Void> delete(@PathVariable("id") Integer id){
        return this.moodService.deleteMood(id);
    }
    @PostMapping("/update")
    public R<Void> update(@RequestBody @Validated(UpdateGroup.class) MoodVO moodVO){
        return this.moodService.updateMood(moodVO);
    }
}
